<?php
/**
 * 用户模型
 */
class User extends CI_Model {
    
    public function __construct() {
        parent::__construct();
    }
    
    /**
     * 添加用户
     */
    public function addUser($username, $password) {
        $data = array('username'=>$username, 'password'=>md5($password));
        return $this->db->insert('user',$data);
    }
    
    /**
     * 修改用户
     * @param $uid
     * @param $data array
     */
    public function updateUser($uid, $data) {
        $this->db->where('uid', $uid);
        return $this->db->update('user', $data);
    }
    
    /**
     * 删除用户
     */
    public function delUser($uid) {
        $data = array('uid'=>$uid);
        return $this->db->delete('user',$data);
    }
    
    
    /**
     * 获取用户
     * @param $condition array
     * @param $row 取单条记录
     */
    public function getUser($condition, $offset, $pagesize, $row = TRUE) {
       
       $res = $this->db->get_where('user',$condition,$pagesize,$offset);
       
       if($row) {
           return $res->row_array();
       }
       
       return $res->result_array();
    }
}